package service;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.anyInt;
import org.junit.jupiter.api.Test;
import org.mockito.BDDMockito;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import com.test.AbstractTransactionalTests;
import org.springframework.stereotype.Service;

@Service
class UserServiceImplTest extends AbstractTransactionalTests{
    @Autowired
    private UserService userService;
    //模拟第三方接口UsexService对象
    private UsexService usexService = Mockito.mock(UsexService.class);
    @Test
    void testGetOne() {
        int uid = 1;
        String expectedUsex = "男";
        /*given是BDDMockito的一个静态方法，用来模拟一个Service方法调用返回，anyInt()表示可以传入任何参数，willReturn方法说明这个调用将返回男。*/
        BDDMockito.given(usexService.getUsex(anyInt())).willReturn(expectedUsex);
        assertEquals(expectedUsex, userService.getOne(uid).getUsex(),"测试失败，与期望值不一致");
    }
}
